﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Semantics.Silverlight;

namespace SilverlightParser.Web.Backend
{
    public class RemotableDialogueProxy
    {
        string Contact;
        public RemotableDialogueProxy(string contact)
        {
            this.RemoteDialogue = Remoter.GetRemoter().GetRemotableDialogue(contact);
            this.Contact = contact;
        }
        Semantics.Distribute.RemotableDialogue RemoteDialogue;
        Semantics.Distribute.DialogueInput ToRemote(string contact, DialogueInput input)
        {
            Semantics.Distribute.DialogueInput remoteinput = new Semantics.Distribute.DialogueInput();
            remoteinput.Input = input.Input;
            remoteinput.Contact = contact;
            return remoteinput;
        }
        public DialogueResult Dialogue(DialogueInput input, string contact)
        {
            DialogueResult result = new DialogueResult();
            try
            {
                Semantics.Distribute.DialogueResult remoteresult = this.RemoteDialogue.Dialogue(ToRemote(contact, input));
                result.Response = remoteresult.Response;
                result.Success = true;
            }
            catch (Exception exp)
            {
                result.Error = new Error();
                result.Error.Exception = exp;
                result.Error.Stack = exp.StackTrace;
                result.Success = false;
            }
            return result;
        }
    }
}